import http from '../utils/axios';


//商品列表
export const baseUrl = 'http://dsq.ljc.icu:8080/'
/* export const baseUrl = 'http://172.16.110.80:8080/' */
/* export const baseUrl = 'http://1.14.123.156:8080/' */  //云服务器
/*  */

//首页
const welUrl = 'http://dsq.ljc.icu:8080'



interface dataType {
    limit: number,
    page: number,

}
/* 商品详情 */
interface Data {
    key: React.Key;
    goodsId: string;//商品序号
    goodsImg: string;//商品图片
    goodsName: string;//商品名字
    goodsSerNum: number;//商品货号
    goodsPriceRange: string;//商品价格区间
    categoryName: string;//类别
    brandName: string;//品牌名
    goodsBrandId: number;//品牌id
    goodsStatus: string;//是否上架
    goodsSell: string;//销量

}

interface ListType {
    data: Data[]
}

//获取所有商品
export const getShopList = (data: dataType) => {
    return http.post<ListType>(baseUrl + '/shopping/goods/getListFindByCon', data)
}
//获取商品状态数量
export const getStateNum = (params?: { status: number }) => {
    return http.get<number>(baseUrl + '/shopping/goods/getGoodsNum', params)
}

interface getClassificationType {
    categoryId: number,
    categoryName: string
}
//分类查询第一类
export const getClassificationOne = (params?: { id: number }) => {
    return http.get<getClassificationType[]>(baseUrl + '/shopping/category/getParentList', params)
}
//分类查询第二类
export const getClassificationTwo = (params?: { id: number }) => {
    return http.get<getClassificationType[]>(baseUrl + '/shopping/category/getList', params)
}
//获取所有品牌名

interface BrandNameType {
    brandId: number,
    brandName: string
}

export const getBrandName = () => {
    return http.get<BrandNameType[]>(baseUrl + '/shopping/brand/getList')
}


//按查询商品

/* 查询接口 */
interface SearchType {
    limit: number,
    page: number,
    goodsName?: string,
    goodsSerNum?: string
    brandName?: string,
    goodsBrandId?: string
    goodsStatus?: string,
    goodsCategoryId?: string,
}

export const getSearchGood = (data: SearchType) => {
    return http.post<ListType>(baseUrl + '/shopping/goods/getListFindByCon', data)
}


//通过商品ID查看商品信息
interface getGood {
    id: number | undefined
}
export const getGoodInfo = (data: getGood) => {
    return http.post<Data>(baseUrl + '/shopping/sku/getListByGoodsId', data)
}
//编辑
interface modifyType {
    goodsId: number,
    goodsName?: string,
    goodsSerNum?: string,
    goodsPriceRange?: string,
    categoryName?: string,
    brandName?: string,
    goodsStatus?: string,
    goodsSell?: number
}


export const getModify = (data: modifyType) => {
    return http.post<Data>(baseUrl + '/shopping/goods/updateGoods', data)
}

//批量操作/删除
interface batchType {
    status: string,
    categoryA?: number
    ids: number[]
}
export const getBatch = (data: batchType) => {
    return http.post<Data>(baseUrl + '/shopping/goods/updateStatus', data)
}
//排序方式
interface sortType {
    limit: number,
    name: string,
    orderNum: string,
    page: number
}


export const getSort = (data: sortType) => {
    return http.post<ListType>(baseUrl + '/shopping/goods/getListFindByCon', data)
}

//添加商品



export const addShop = (data: Data) => {
    return http.post<ListType>(baseUrl + '/shopping/goods/insertGoods', data)
}










//获取首页数据（除图之外）
interface systemData {
    orderTotal: number,
    payMoney: number,
    payMoneyW: number,
    payMoneyY: number,
}
interface pendingData {
    noPayment: number,
    payment: number,
    pendingReturn: number,
    shipments: number,
    noShipments: number,
    noReplacement: number,
}
interface productData {
    goodsTotal: number,
    inventory: number,
    listed: number,
    noListed: number,

}
interface userData {
    newUser: number,
    newUserM: number,
    newUserY: number,
    vipTotal: number,

}

interface WelType {
    systemHome: systemData,
    pending: pendingData,
    productView: productData,
    userView: userData,
}

export const getWelcome = () => {
    return http.get<WelType>(welUrl + '/system/Home2')
}
//获取订单统计图数据
interface CartogramInfo {
    endTime?: string,
    startTime?: string,
    time?: string
}
interface CartogramType {
    total: Cartogram[],
    compare: Cartogram2
}
interface CartogramType2 {
    nextTotal: Cartogram[],
    nextCompare: Cartogram2
}
interface Cartogram {
    orderNum: number,
    time: string,

}
interface Cartogram2 {
    orderM: number,
    orderW: string,
    toLastMonth: number,
    toLastWeek: number
}



export const getCartogram = (data: CartogramInfo) => {
    return http.post<CartogramType>(welUrl + '/system/Home', data)
}
export const getOrderCartogram = (data: CartogramInfo) => {
    return http.post<CartogramType2>(welUrl + '/system/Home1', data)
}
//获取指定时间段的订单数据
export const getTimesCartogram = (data: CartogramInfo) => {
    return http.post<CartogramType>(welUrl + '/system/Home', data)
}
//获取指定时间段的销售额数据
export const getTimesOrder = (data: CartogramInfo) => {
    return http.post<CartogramType2>(welUrl + '/system/Home1', data)
}

//账号设置
interface SettingInfo {
    admin?: string,
    email?: string,
    name?: string,
    newPassword?: string,
    oldPassword?: string,
    phone?: string
}


export const Setting = (data: SettingInfo) => {
    return http.post(welUrl + '/system/setUser', data)
}
